package collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

/**
 * @author DBX
 * @effect 集合转化为数组
 *          Collection提供了方法toArray可以将当前集合转化为一个数组
 * @date 2021/09/03/17:04
 */
public class CollectionToArrayDemo {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();
        c.add("1");
        c.add("2");
        c.add("3");
        c.add("4");
        c.add("5");
        System.out.println("集合："+c);

        String[] arr = c.toArray(new String[c.size()]);
        System.out.println("数组："+ Arrays.toString(arr));

    }
}
